package Java练习.综合练习;

import java.util.Scanner;

public class 二维数组练习 {
    public static void main(String[] args) {
        //定义一个动态的二维数组
        int[][] money=new int[4][3];
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < money.length; i++) {
            for (int i1 = 0; i1 < money[i].length; i1++) {
                System.out.print("请输入第"+(i+1)+"个季度,第"+(i1+1)+"个月的营业额:");
                int input=sc.nextInt();
                money[i][i1]=input;
            }
        }
        //计算每个季度的总营业额和全年的总营业额.
        //记录每个季度的营业额
        int count=0;
        for (int i = 0; i < money.length; i++) {
            count+=add(money[i]);
            System.out.println("第"+(i+1)+"个季度的总营业额为:"+add(money[i]));
        }
        System.out.println("全年总营业额为:"+count);
    }
    //定义一个对数组求和的函数
    public static int add(int[] num){
        int count=0;
        for (int i = 0; i < num.length; i++) {
            count+=num[i];
        }
        return count;
    }
}
